C++ const and Immutability: An Empirical Study of Writes-Through-const

نویسندگان

  • Jon Eyolfson
  • Patrick Lam
چکیده

The ability to specify immutability in a programming language is a powerful tool for developers, enabling them to better understand and more safely transform their code without fearing unintended changes to program state. The C++ programming language allows developers to specify a form of immutability using the const keyword. In this work, we characterize the meaning of the C++ const qualifier and present the ConstSanitizer tool, which dynamically verifies a stricter form of immutability than that defined in C++: it identifies const uses that are either not consistent with transitive immutability, that write to mutable fields, or that write to formerly-const objects whose const-ness has been cast away. We evaluate a set of 7 C++ benchmark programs to find writes-through-const, establish root causes for how they fail to respect our stricter definition of immutability, and assign attributes to each write (namely: synchronized, not visible, buffer/cache, delayed initialization, and incorrect). ConstSanitizer finds 17 archetypes for writes in these programs which do not respect our version of immutability. Over half of these seem unnecessary to us. Our classification and observations of behaviour in practice contribute to the understanding of a widely-used C++ language feature. 1998 ACM Subject Classification D.3.3 Language Constructs and Features

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

C++ const and Immutability: An Empirical Study of Writes-Through-const (Artifact)

This artifact is based on ConstSanitizer, a dynamic program analysis tool that detects deep immutability violations through const qualifiers. Our tool instruments any code compiled by clang with the -fsanitizer=const flag. Our implementation includes both instrumentation of LLVM code and a runtime library to support our analysis. The provided package includes our tool and all experiments used i...

متن کامل

HOLDER NORMS 4D examples including the Hopf Map

> with(liesymm):with(linalg):setup(x,y,z,t,s,Ct);deforms(a=const,b=const,c=cons t,d=const,p=const,n=const,k=const,omega=const,e=const); Warning, new definition for close Warning, new definition for norm Warning, new definition for trace [ ] , , , , , x y z t s Ct ( ) deforms , , , , , , , , = a const = b const = c const = d const = p const = n const = k const = ω const = e const HOLDER NORMS 4D...

متن کامل

Supplemental Material: Path Space Regularization for Holistic and Robust Light Transport

#include // smallpt, a Path Tracer by Kevin Beason, 2008 #include // Make : g++ -O3 -fopenmp smallpt.cpp -o smallpt #include //Note typedef struct Vec { // Usage: time ./explicit 16 && xv image.ppm double x, y, z; // position, also color (r,g,b) Vec(double x_=0, double y_=0, double z_=0){ x=x_; y=y_; z=z_; } Vec operator+(const Vec &b;) const { return Vec(x+b.x,y+b....

متن کامل

Cmpsci 377 Operating Systems 3.1 Operator Overloading in C++

It allows you to provide an intuitive interface to users of your class, plus makes it possible for templates to work equally well with classes and built-in/intrinsic types. Operator overloading allows C/C++ operators to have user-defined meanings on user-defined types (classes). Overloaded operators are syntactic sugar for function calls: Fred f(const Fred& a, const Fred& b, const Fred& c) { re...

متن کامل

NAG Library Function Document nag_hier_mixed_init (g02jcc)

#include #include void nag_hier_mixed_init (Nag_OrderType order, Integer n, Integer ncol, const double dat[], Integer pddat, const Integer levels[], const double y[], const double wt[], const Integer fixed[], Integer lfixed, Integer nrndm, const Integer rndm[], Integer lrndm, Integer *nff, Integer *nlsv, Integer *nrf, double rcomm[], Integer lrcomm, Integer icomm[], Integer l...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2016